Skip to content

docs: modernize type annotations to Python 3.10+ built-in generics#5995

Open
FBISiri wants to merge 1 commit into
crewAIInc:mainfrom
FBISiri:docs/modernize-type-annotations
Open

docs: modernize type annotations to Python 3.10+ built-in generics#5995
FBISiri wants to merge 1 commit into
crewAIInc:mainfrom
FBISiri:docs/modernize-type-annotations

Conversation

@FBISiri
Copy link
Copy Markdown

@FBISiri FBISiri commented Jun 1, 2026

Summary

Since crewAI requires Python ≥3.10 (pyproject.toml), code examples in documentation should use modern built-in generic types instead of importing from typing.

Changes

Across 9 documentation files (quickstart, guides, learn, observability):

Before (typing module) After (built-in)
List[X] list[X]
Dict[K, V] dict[K, V]
Tuple[X] tuple[X]
Optional[X] X | None
Union[X, Y] X | Y

This removes unnecessary from typing import ... lines and aligns documentation with:

  • PEP 585 — Type Hinting Generics In Standard Collections
  • PEP 604 — Allow writing union types as X | Y

Files modified

  • docs/en/quickstart.mdx
  • docs/en/guides/crews/first-crew.mdx
  • docs/en/guides/flows/first-flow.mdx
  • docs/en/guides/flows/mastering-flow-state.mdx
  • docs/en/guides/concepts/evaluating-use-cases.mdx
  • docs/en/learn/conditional-tasks.mdx
  • docs/en/learn/custom-llm.mdx
  • docs/en/learn/bring-your-own-agent.mdx
  • docs/en/observability/braintrust.mdx

Why

New users copy-pasting from docs get cleaner, more modern Python code. The old typing imports are unnecessary boilerplate since Python 3.10, which is crewAI's minimum supported version.

Summary by CodeRabbit

  • Documentation
    • Updated Python code examples across guides, tutorials, and learning materials to use modern Python 3.10+ type annotation syntax
    • Replaced legacy typing module type hints with built-in generic types and union syntax for improved code clarity
    • Removed unused type imports from code snippets across documentation

Since crewAI requires Python >=3.10 (pyproject.toml), code examples in
documentation should use modern built-in generic types instead of
importing from typing:

- List[X] → list[X]
- Dict[K, V] → dict[K, V]
- Tuple[X] → tuple[X]
- Optional[X] → X | None
- Union[X, Y] → X | Y

This removes unnecessary typing imports and aligns documentation with
PEP 585 (built-in generics) and PEP 604 (union type operator).

Updated 9 documentation files across quickstart, guides, learn, and
observability sections.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: de039a87-9dc5-4604-b769-4d2e7c6d81ad

📥 Commits

Reviewing files that changed from the base of the PR and between 4dafb05 and 1c10747.

📒 Files selected for processing (9)
  • docs/en/guides/concepts/evaluating-use-cases.mdx
  • docs/en/guides/crews/first-crew.mdx
  • docs/en/guides/flows/first-flow.mdx
  • docs/en/guides/flows/mastering-flow-state.mdx
  • docs/en/learn/bring-your-own-agent.mdx
  • docs/en/learn/conditional-tasks.mdx
  • docs/en/learn/custom-llm.mdx
  • docs/en/observability/braintrust.mdx
  • docs/en/quickstart.mdx
💤 Files with no reviewable changes (1)
  • docs/en/guides/concepts/evaluating-use-cases.mdx

📝 Walkthrough

Walkthrough

This PR modernizes Python type annotations across nine documentation guides to use Python 3.10+ syntax. Typing imports are removed, List/Dict are converted to built-in list/dict, and Optional/Union are replaced with union syntax (X | None, X | Y).

Changes

Type Annotation Modernization

Layer / File(s) Summary
Import cleanup and basic generic conversions
docs/en/guides/concepts/evaluating-use-cases.mdx, docs/en/guides/crews/first-crew.mdx, docs/en/guides/flows/first-flow.mdx, docs/en/guides/flows/mastering-flow-state.mdx, docs/en/learn/conditional-tasks.mdx, docs/en/learn/bring-your-own-agent.mdx, docs/en/observability/braintrust.mdx, docs/en/quickstart.mdx
Remove unused typing module imports (List, Dict, Optional) and convert generic type annotations to built-in syntax: List[X]list[X] and Dict[X, Y]dict[X, Y]. Updates apply to model fields and class attributes across guides covering crews, flows, state management, conditional tasks, and adapters.
Optional/Union to union syntax conversion
docs/en/learn/bring-your-own-agent.mdx, docs/en/learn/custom-llm.mdx, docs/en/guides/flows/mastering-flow-state.mdx
Convert method signatures and type hints from Optional[X] to X | None and Union[X, Y] to X | Y syntax. Updates include adapter pattern signatures (MyCustomAgentAdapter.__init__, configure_tools), LLM method signatures (CustomLLM.call, CustomAuthLLM.__init__), and optional state fields like datetime | None.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

documentation, size/M

Suggested reviewers

  • greysonlalonde
  • lucasgomide

🐰 With modernized type hints so clean and bright,

Our docs now sparkle in Python's light,

List becomes list, Dict turns small,

Union syntax answers the call,

3.10+ looking mighty tight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'docs: modernize type annotations to Python 3.10+ built-in generics' accurately and concisely summarizes the main objective of the pull request, which is to update documentation code examples to use modern Python 3.10+ built-in generic and union syntax across nine documentation files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant